<?xml version="1.0" encoding="UTF-8"?>

<xs:schema id="schema.sph"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://a42.vodafone.com/versions/sph/v1"
    xmlns:a42ns="http://a42.vodafone.com/versions/a42/v1"
    xmlns:sc2ns="http://a42.vodafone.com/versions/sc2/v1"
    xmlns:sphns="http://a42.vodafone.com/versions/sph/v1"
    xmlns:spans="http://a42.vodafone.com/versions/spa/v1"
    elementFormDefault="qualified"
    >

    <!-- Import the common types for A42 resources. -->
    <!-- <xs:include schemaLocation="a42.xsd" /> -->
    <xs:import schemaLocation="a42.xsd" namespace="http://a42.vodafone.com/versions/a42/v1" />
    <!-- Import the referenced types for simple content catalog resources. -->
    <!-- <xs:include schemaLocation="sc2.xsd" /> -->
    <xs:import schemaLocation="sc2.xsd" namespace="http://a42.vodafone.com/versions/sc2/v1" />
    <!-- Import the referenced types for simple purchase API resources. -->
    <!-- <xs:include schemaLocation="spa.xsd" /> -->
    <xs:import schemaLocation="spa.xsd" namespace="http://a42.vodafone.com/versions/spa/v1" />
    
        <xs:defaultOpenContent mode="interleave">
        <xs:any namespace="##any" processContents="lax" />
        </xs:defaultOpenContent>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    <!-- Definition of XML representations for purchase history resources and related DTOs. -->
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <!-- Specific link types with defined link relation types. -->
    <xs:complexType name="purchaseHistoriesLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchaseHistories" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchaseHistoryLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchaseHistory" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchasedItemsLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchasedItems" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    <xs:complexType name="purchasedItemLinkType">
        <xs:complexContent>
            <xs:restriction base="a42ns:LinkType">
                <xs:attribute name="rel" type="xs:string" use="required"
                    fixed="http://a42.vodafone.com/rels/simplePurchaseHistory/purchasedItem" />
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <!-- Representation for the service document for this API. -->
    <xs:element name="sphServiceDocument">
        <xs:complexType>
            <xs:all>
                <!-- Root link for all purchase histories only for admin authorization. -->
                <xs:element name="purchaseHistoriesRootLink" type="sphns:purchaseHistoriesLinkType" minOccurs="0" maxOccurs="1" />
                <!-- Root link for particular purchase history only for a provisioned user. -->
                <xs:element name="purchaseHistoryRootLink" type="sphns:purchaseHistoryLinkType" minOccurs="0" maxOccurs="1" />
            </xs:all>
        </xs:complexType>
    </xs:element>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <!-- Representation for a collection resource that aggregates purchase history entities. -->
    <xs:element name="purchaseHistories" type="sphns:purchaseHistoriesType" />
    <xs:complexType name="purchaseHistoriesType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="purchaseHistories" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="sphns:purchaseHistoryLinkType" />
                                <xs:element name="purchaseHistory" type="sphns:purchaseHistoryType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- Representation for a collection resource that aggregates purchase history entities. -->
    <xs:element name="purchasedItems" type="sphns:purchasedItemsType" />
    <xs:complexType name="purchasedItemsType">
        <xs:complexContent>
            <xs:extension base="a42ns:PaginatableResourceType">
                <xs:all>
                    <xs:element name="purchasedItems" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:choice minOccurs="0" maxOccurs="unbounded">
                                <xs:element name="link" type="sphns:purchasedItemLinkType" />
                                <xs:element name="purchasedItem" type="sphns:purchasedItemType" />
                            </xs:choice>
                        </xs:complexType>
                    </xs:element>
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
    <xs:complexType name="embeddedPurchaseHistoryType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="sphns:purchaseHistoryLinkType" />
            <xs:element name="purchaseHistory" type="sphns:purchaseHistoryType" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="embeddedPurchasedItemsType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="sphns:purchasedItemsLinkType" />
            <xs:element name="purchasedItems" type="sphns:purchasedItemsType" />
        </xs:choice>
    </xs:complexType>
    <xs:complexType name="embeddedPurchasedItemType">
        <xs:choice minOccurs="1" maxOccurs="1">
            <xs:element name="link" type="sphns:purchasedItemLinkType" />
            <xs:element name="purchasedItem" type="sphns:purchasedItemType" />
        </xs:choice>
    </xs:complexType>
    
    <!-- To create a new purchase history. This is not a resource, therefore no resourceIdentity element. -->
    <xs:element name="purchaseHistory" type="sphns:purchaseHistoryType" />
    <xs:complexType name="purchaseHistoryType">
        <xs:complexContent>
            <xs:extension base="a42ns:ResourceType">
                <xs:all>
                    <!-- The actual collection of purchased item links. -->
                    <xs:element name="purchasedItems" type="sphns:embeddedPurchasedItemsType" minOccurs="0" maxOccurs="1"/>
                    <!-- The user that owns the purchase history / the purchased-items. -->
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <!-- To create a new purchased item. This is not a resource, therefore no resourceIdentity element. -->
    <xs:element name="purchasedItem" type="sphns:purchasedItemType" />
    <xs:complexType name="purchasedItemType">
        <xs:complexContent>
            <xs:extension base="a42ns:ResourceType">
                <xs:all>
                    <!-- Link to the catalog-item that has been purchased. -->
                    <xs:element name="catalogItem" type="sc2ns:embeddedCatalogItemType" minOccurs="0" maxOccurs="1" />
                    <!-- Link to the purchase-order-item that caused this purchased-item instance. -->
                    <xs:element name="purchaseOrder" type="spans:embeddedPurchaseOrderType" minOccurs="0" maxOccurs="1" />
                    <!-- A link to the user's purchase history root resource. -->
                    <xs:element name="purchaseHistory" type="sphns:embeddedPurchaseHistoryType" minOccurs="0" maxOccurs="1" />
                    <!-- Link to the parent item, will not appear in case it is an item on level 0. -->
                    <xs:element name="parentItem" type="sphns:embeddedPurchasedItemType" minOccurs="0" maxOccurs="1"/>
                    <!-- Links to sub-items that were added afterwards. Can be omitted when there are no sub-items. -->
                    <xs:element name="subItems" type="sphns:embeddedPurchasedItemsType" minOccurs="0" maxOccurs="1"/>
                    <!-- The price the user has paid for this single item. -->
                    <xs:element name="paidPrice" minOccurs="0" maxOccurs="1">
                        <xs:complexType>
                            <xs:all>
                                <xs:element name="value" type="xs:double" minOccurs="0" maxOccurs="1"/>
                                <xs:element name="currency" type="xs:string" minOccurs="0" maxOccurs="1" />
                            </xs:all>
                        </xs:complexType>
                    </xs:element>
                    <!-- The user that owns the purchased-item. -->
                    <xs:element name="userId" type="xs:string" minOccurs="0" maxOccurs="1" />
                    <!-- The number of maximum downloads in case the product is downloadable. Zero or omitted otherwise. -->
                    <xs:element name="maxDownloads" type="xs:unsignedByte" minOccurs="0" maxOccurs="1" />
                    <!-- The number of remaining downloads in case the product is downloadable. Zero or omitted otherwise. -->
                    <xs:element name="remainingDownloads" type="xs:unsignedByte" minOccurs="0" maxOccurs="1" />
                    <!-- Flag to indicate if an associated license has expired. Can be omitted if not applicable. -->
                    <xs:element name="isExpired" type="xs:boolean" minOccurs="0" maxOccurs="1" />
                </xs:all>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    
    <!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
    
</xs:schema>
